<template>
<view class="container">
	<view class="jobinfo">
		<view class="jobtitle">
			<view>{{info.job}}</view>
			<view>正在招聘...</view>
		</view>
		<view class="joblabel">
			<view>{{moneyArr[info.money]}}/月</view>
			<view>|</view>
			<view>{{info.city}}</view>
			<button @click="tdJob()" v-if="!tdShow && role == 2" class="tdJOb">投递该职位</button>
			<button v-else class="tdJOb1">投递该职位</button>
		</view>
	</view>
	
	<view class="jobRemark" v-if="info.remark">
		<view class="remarkTitle">岗位介绍</view>
		<view class="remarkContent">{{info.remark}}</view>
	</view>
	
	<view class="company">
		<view @click="toCompanyDetail" class="companyinfo">
			<image v-if="info.imgs.length > 0" :src="imgUrl+info.imgs[0]"></image>
			<image v-else :src="pubImg"></image>
			<view class="companyname">
				<view>{{info.name}}</view>
				<view>联系人:{{info.contacts}} </view>
				<view>
					公司地址:{{info.address}}</view>
			</view>
		</view>
	</view>	
	<view class="jobdetail">
		<view class="jobtitle">公司介绍</view>
	</view>
	<view :class="[info.latitude ? '' : 'marginBottom']" class="jobcontent">
		<image v-if="info.imgs.length > 0" v-for="(item,index) in info.imgs" :key="index" :src="imgUrl+item"></image>
		<view>暂无简介..</view>
	</view>
	<!-- <view class="mapContent" v-if="info.latitude">
		<view class="map">公司位置</view>
		<button type="primary" @click="navigate">导航</button>
	</view>	
	<view class="page-section1" v-if="info.latitude">
		<map style="width:96%;height:200px;margin-left:2%"
			:latitude="latitude"
			:longitude="longitude"
			:markers="markers"
			show-location>
		</map>
	</view> -->
	
	<view class="weixinmao-foot" v-if="role == 2">
		<button v-if="cShow" class="footerbuttons1">收藏岗位</button>
	    <button @click="CompanyCollection" v-else class="footerbuttons">收藏岗位</button>
	    <button @click="toUser(info.uid)" class="footerbuttons">立即沟通</button>
	    <button @click="share" class="footerbuttons">分享职位</button>
	</view>
</view>
</template>
<script>
import request from '@/util/request.js'	
export default {
	data() {
		return {
			pubImg:'/static/img1/noup3.jpg',
			imgUrl:this.url,
			info:[],
			tdShow:false,
			moneyArr:['面议','5k以下','5k~8k','8k~10k','10k以上'],
			cShow:false,
			latitude:'38.9375',
			longitude:'117.3571',
			markers: [{
			  id: 1,
			  latitude: '38.9375',
			  longitude: '117.3571',
			}],
			role:0
		}
	},
	onLoad:function(e){
		uni.showLoading({
		    title: '加载中'  
		});
		this.role = uni.getStorageSync('role'),
		this.getCompanyInfo(e.id)
		this.getCompanyCollection(e.id)
		this.getJobTd(e.uid)
	},
	methods: {
		getCompanyInfo:function(id){
			var data = {'id':id}
			var that = this
			request({
				url: 'company/info',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.code == 1){
						// var markers = that.markers
						// markers[0].latitude = res.data.data.latitude
						// markers[0].longitude = res.data.data.longitude
						that.info = res.data.data
						// that.latitude = res.data.data.latitude
						// that.longitude = res.data.data.longitude
						// that.markers = markers
					}
				}
			})
		},
		getJobTd:function(uid){
			var data = {
				'uid':uni.getStorageSync('uid'),
				'company_uid':uid,
			}
			var that = this
			request({
				url: 'delivery/is_true',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						that.tdShow = true
					}
				}
			})
		},
		getCompanyCollection:function(id){
			var data = {
				'uid':uni.getStorageSync('uid'),
				'rid':id,
				'type':2
			}
			var that = this
			request({
				url: 'collection/info',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
					    that.cShow = true
					}
				},
			})
		},
		tdJob:function(){
			var data = {
				'uid':uni.getStorageSync('uid'),
			    'company_uid':this.info.uid
			}
			var that = this
			request({
				url: 'delivery/add',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title: '投递成功!!',
							icon: "none", 
							position:'bottom',
						});
						that.tdShow = true
					}
				}
			})
		},
		CompanyCollection:function(){
			var that = this;
			var data = {
				'uid':uni.getStorageSync('uid'),
				'rid':this.info.id,
				'type':2
			}
			request({
				url: 'collection/add',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title: '岗位收藏成功!!',
							icon: "none", 
							position:'bottom',
						});
						that.cShow = true
					}
				}
			})
		},
		toUser:function(uid){
			uni.navigateTo({
				url: '/pages/message/online/toCompany?touid='+uid
			})
		},
		navigate:function(){
			console.log('导航')
			// var that = this
			// uni.getLocation({//获取当前经纬度
			//   type: 'wgs84', //返回可以用于wx.openLocation的经纬度，官方提示bug: iOS 6.3.30 type 参数不生效，只会返回 wgs84 类型的坐标信息  
			//   success: function (res) {
			// 	  console.log(res)
			// 	// wx.openLocation({//​使用微信内置地图查看位置。
			// 	//   latitude:Number(that.data.latitude),//要去的纬度-地址
			// 	//   longitude:Number(that.data.longitude),//要去的经度-地址
			// 	//   name:that.data.info.name,
			// 	//   address:that.data.info.address,
			// 	//   scale:18
			// 	// })
			//   }
			// })
		},
		share:function(){
			if(this.info.imgs){
				var img = this.imgUrl + this.info.imgs[0]
			}else{
				var img = '/static/img1/noup3.jpg'
			}
			uni.share({
			    provider: "weixin",
			    scene: "WXSceneSession",
			    type: 5,
			    imageUrl:img,
			    title: '人才招聘',
				miniProgram: {
					id: 'gh_42fb5eed1670',
					path: 'pages/index/index',
					type: 0,
					webUrl: 'https://www.tymyztc.com'
				},
				success: ret => {
					console.log(JSON.stringify(ret));
				}
			});
		}
	},
}
</script>
<style scoped>
	@import url("./css/info.css");
</style>